#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>

using namespace std;

inline long long ckjread()
{
	long long s=0,w=1,ch=getchar();
	while(ch<'0'||ch>'9') ch=='-'?w=-1,ch=getchar():ch=getchar();
	while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return s*w;
}

void jynwriten(long long x)
{
	x>9?jynwriten(x/10),putchar(x%10|48):putchar(x|48);
}

int n;
map<string,int> who;
char tmp[100005],ip[100005];

inline int getlen(long long x)
{
	if(x==0)
	{
		return 1;
	}
	int res=0;
	while(x>0)
	{
		x/=10;
		res++;
	}
	return res;
}

inline bool check()
{
	int len=strlen(ip);
	int dcnt=0,mhcnt=0;
	for(int i=0;i<len;i++)
	{
		dcnt+=ip[i]=='.';
		mhcnt+=ip[i]==':';
	}
	if(dcnt!=3||mhcnt!=1)
	{
		return false;
	}
	long long a,b,c,d,port;
	if(sscanf(ip,"%lld.%lld.%lld.%lld:%lld",&a,&b,&c,&d,&port)!=5)
	{
		return false;
	}
	int alen=0,blen=0,clen=0,dlen=0,portlen=0;
	int cnt=1;
	for(int i=0;i<len;i++)
	{
		if(ip[i]=='.'||ip[i]==':')
		{
			cnt++;
			continue;
		}
		cnt==1?alen++:(cnt==2?blen++:(cnt==3?clen++:(cnt==4?dlen++:portlen++)));
	}
	if(alen!=getlen(a)||blen!=getlen(b)||clen!=getlen(c)||dlen!=getlen(d)||portlen!=getlen(port))
	{
		return false;
	}
	return (a>=0&&a<=255)&&(b>=0&&b<=255)&&(c>=0&&c<=255)&&(d>=0&&d<=255)&&(port>=0&&port<=65535);
}

int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	n=ckjread();
	for(int i=1;i<=n;i++)
	{
		scanf("%s%s",tmp,ip);
		if(!check())
		{
			puts("ERR");
			continue;
		}
		if(tmp[0]=='S')
		{
			if(who.find(ip)!=who.end())
			{
				puts("FAIL");
				continue; 
			}
			who[ip]=i;
			puts("OK");
		}
		else
		{
			if(who.find(ip)==who.end())
			{
				puts("FAIL");
				continue;
			}
			jynwriten(who[ip]);
			putchar('\n');
		}
	}
	return 0;
}
